const app = getApp()

Page({
  onLoad() {
    let app = getApp();
    //this.data.disabled = app.globalData.manual_disabled;
    this.data.src = app.globalData.pic_src;
  },
  data: {
    classifyResult: "识别结果将显示在此处",
    src: null,
    disabled: false,
    inputValue: ""
  },
  bindKeyInput: function (e) {
    this.setData({
      inputValue: e.detail.value
    })
  },
  manulCheck(){
    if(this.data.src){
      wx.uploadFile({
        url: 'http://49.233.9.115/manual_classify', 
        filePath: this.data.src,
        name: 'uploadfile_ant',
        formData: {
          'hint':this.data.inputValue
        },
        success: (res)=>{
          console.log('upload success')
          let data = res.data
          let parsed_data = JSON.parse(data)
          console.log(data)
          this.setData({
            classifyResult:parsed_data['result']
          })
        },
        fail:()=>{
          console.log('failed')
        }
      })
    }else{
      wx.request({
        url: 'http://49.233.9.115/manual_classify_nopic',
        data:{
          hint:this.data.inputValue
        },
        method:'POST',
        success: (res)=>{
          console.log('upload success')
          let data = res.data
          console.log(data)
          let parsed_data = data
          this.setData({
            classifyResult:parsed_data['result']
          })
        },
        fail:()=>{
          console.log('failed')
        }
      })
    }
  },
})